<?php
include get_theme_file_path() . '/inc/style.php';
include get_theme_file_path() . '/inc/CustomerFeedback.php';

// 自定义LOGO
function init()
{
    add_theme_support(
        'custom-logo',
        array(
            'height'      => 60, // 高度
            'width'       => 60, // 宽度
        )
    );
    add_theme_support('post-thumbnails');
    // 声明支持woocommerce
    add_theme_support('woocommerce');
}
add_action('after_setup_theme', 'init');

// 去除wcc自带的样式，__return_empty_array是wp自带的函数，返回空数组
add_filter('woocommerce_enqueue_styles', '__return_empty_array');
// 去除wcc自带的JS
remove_action('wp_enqueue_scripts', [\WC_Frontend_Scripts::class, 'load_scripts']);

// 顶部导航栏菜单
add_action('after_setup_theme', 'register_menus');
function register_menus()
{
    // 注册菜单导航
    register_nav_menus([
        'top-menu'  =>  '顶部导航',
        'buttom-menu'   =>  '底部导航',
        'link-menu' =>  '友情链接',
    ]);
}
add_filter('nav_menu_link_attributes', 'add_class_and_data_to_nav_menu_link', 10, 3);
function add_class_and_data_to_nav_menu_link($atts, $item, $args)
{
    // 检查导航菜单是否有"top-menu"的名称，根据您的实际菜单名称进行更改
    if ($args->theme_location === 'top-menu') {
        // 添加class属性
        $atts['class'] = 'nav-link';
    }
    return $atts;
}

// 设置浏览量
function set_views($post_id)
{
    // 详情页面才进行设置
    if (is_single() && !empty($post_id)) {
        $view_count = get_post_meta($post_id, '_views', true);
        $view_count = $view_count ? $view_count : 0;
        $view_count = $view_count + 1;
        update_post_meta($post_id, '_views', $view_count);
    }
}

// 显示浏览量
function get_views($post_id)
{
    $view_count = get_post_meta($post_id, '_views', true);
    $view_count = $view_count ? $view_count : 0;
    return $view_count;
}

if (function_exists('z_taxonomy_image_url')){
    echo z_taxonomy_image_url();
}